<?php
#### PRINT ARRAY ###############################################################
// Format the output of print_r and return it
function print_array($array) {
	return '<pre>'.print_r($array, TRUE).'</pre>';
}

#### BOX #######################################################################
// A quick wrapper method to output a box
function box($title = NULL, $body) {
	$tpl = new template('box', 'common');

	$tpl->assign('TITLE', $title);
	$tpl->assign('BODY', $body);

	return $tpl->output();
}

#### VARIABLE ##################################################################
// Get common predefined variables (super globals)
function variable(&$pass_var, $index, $type, $default = NULL) {

	switch ($type) {
		case 'get':
			$pass_var = (isset($_GET[$index]) ? $_GET[$index] : $default);
			break;
		case 'post':
			$pass_var = (isset($_POST[$index]) ? $_POST[$index] : $default);
			break;
		case 'files':
			$pass_var = (isset($_FILES[$index]) ? $_FILES[$index] : $default);
			break;
		case 'session':
			$pass_var = (isset($_SESSION[$index]) ? $_SESSION['lf'][$index] : $default);
			break;
		case 'cookie':
			$pass_var = (isset($_COOKIE[$index]) ? $_COOKIE[$index] : $default);
			break;
		case 'request':
			$pass_var = (isset($_REQUEST[$index]) ? $_REQUEST[$index] : $default);
			break;
	}

}

#### Slide #####################################################################
// A quick wrapper for generating show/hide sliding jQuery JS
function slider($hidden_div_element, $toggle_item_element) {
	return '<script type="text/javascript">
		$(document).ready(function() {
			$("'.$hidden_div_element.'").hide();
			$("'.$toggle_item_element.'").attr("style", "cursor: pointer");
			$("'.$toggle_item_element.'").click(function() {
				$("'.$hidden_div_element.'").slideToggle();
			});
		});

	</script>';
}

#### SEF #######################################################################
// Makes URI's safe kids
function sef($name) {
	// Get rid of anything that isn't "alphanumeric _ - ." or a space
	$name = preg_replace('([^[:alnum:]. _-])', '', strtolower(trim($name)));
	// Get rid of anything that isn't "alphanumeric _ - ." and replace it with _
	return preg_replace('([^[:alnum:]._-])', '-', $name);
}
?>